using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;

using NDF.XnaLibrary.Models;
using System.IO;
using System.Diagnostics;

namespace NDF.SkinnedModelProcessor
{
	[ContentProcessor(DisplayName = "NDF - Basic Shader Processor")]
	public class NDF_BasicShaderProcessor : ModelProcessor
	{
		protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
		{
			EffectMaterialContent newMaterial = new EffectMaterialContent();
			string effectPath = Path.GetFullPath("NDF-Effect.fx");
			newMaterial.Effect = new ExternalReference<EffectContent>(effectPath);

			if (material is BasicMaterialContent)
			{
				BasicMaterialContent basic = material as BasicMaterialContent;

				if (basic.Texture != null)
					newMaterial.Textures.Add("Texture0", basic.Texture);
				if (basic.OpaqueData != null || basic.OpaqueData.Count == 0)
				{
					if (basic.DiffuseColor.HasValue)
						newMaterial.OpaqueData.Add("DiffuseColor", basic.DiffuseColor);
					if (basic.SpecularColor.HasValue)
						newMaterial.OpaqueData.Add("SpecularColor", basic.SpecularColor);
					if (basic.SpecularPower.HasValue)
						newMaterial.OpaqueData.Add("SpecularPower", basic.SpecularPower);
					if (basic.EmissiveColor.HasValue)
						newMaterial.OpaqueData.Add("EmmisiveColor", basic.EmissiveColor);
				}
			}

			return base.ConvertMaterial(newMaterial, context);
		}
	}
}